package cn.tedu._03vehicle.base.interceptors;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import java.time.LocalDateTime;
@Slf4j
public class TimeAccessInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("进入到限定访问时间的拦截器");
        LocalDateTime now = LocalDateTime.now();
        int hour = now.getHour();
        if (hour < 10 || hour > 22) {
           // http:localhost:8080/error. html
           // response.sendRedirect("/error.html");
           // return false;
            throw new RuntimeException("当前时间不允许访问");
        }
        return true;
    }

}
